home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Over 1,000 Windows 95 Programs
/
Over 1000 Windows 95 Programs (Microforum) (Disc 1).iso
/
1244
/
procapp1.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-06-17
|
4KB
|
151 lines
#include <windows.h>
#include "procbox.h"
int CALLBACK _export PBCallback(HWND, int , LPARAM);
////////////////////////////////////////////////////////////////////////////////
//
// PROCAPP1.C - Demonstrates use of ProcessBox Single Callback Interface
//
// - Contains code for
// - WinMain Entry Point
// - WndProc
LRESULT FAR PASCAL _export WndProc(HWND, UINT, WPARAM, LPARAM);
char szAppName[] = "PROCAPP1";
char szWindowText[] = "ProcessBox - Single Callback Modal Interface Demo";
/////////////////////////////////////////////////
//
//
// WndProc
//
LRESULT FAR PASCAL _export WndProc (HWND hwnd, UINT message,
WPARAM wParam, LPARAM lParam)
{
FARPROC lpfnPBCallback;
char szText[64];
switch (message)
{
case WM_KEYDOWN:
case WM_LBUTTONDOWN:
lpfnPBCallback = MakeProcInstance((FARPROC)PBCallback, GetWindowWord(hwnd, GWW_HINSTANCE));
wsprintf(szText, "Returned: %d",
ProcessBox(hwnd, "Processing...", lpfnPBCallback)); // it's that easy!
MessageBox(hwnd, szText, NULL, NULL);
FreeProcInstance(lpfnPBCallback);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc (hwnd, message, wParam, lParam );
}
///////////////////////////////////////////////////////////
//
// The Process Box Callback
//
//
int CALLBACK _export PBCallback(HWND hwndPB, int iCode, LPARAM lUserData)
{
static i;
long j;
switch (iCode)
{
case PBC_OPEN:
// allocate memory here
i=0;
return TRUE;
case PBC_CLOSE:
// free memory here
return TRUE;
case PBC_CANCEL:
return ( MessageBox(NULL, "Really cancel operation?", "Message Box",
MB_APPLMODAL|MB_YESNO)==IDYES ? TRUE : FALSE );
case PBC_PROCESS:
for (j=0; j<0xEFF; j++); // processing !
i++;
if (i>10000)
return PBCR_END;
if (i==5000)
SetWindowText(hwndPB, "Reached halfway!");
SendMessage(hwndPB, PM_SETGAUGE, i/100, 0l);
return PBCR_CONTINUE;
default:
i++;
}
return TRUE;
}
/////////////////////////////////////////////////
//
//
// WinMain - Entry Point
//
//
int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
LPSTR lpszCmdParam, int nCmdShow)
{
MSG msg ;
WNDCLASS wndclass ;
HWND hwnd;
if (!hPrevInstance)
{
wndclass.style = NULL ;
wndclass.lpfnWndProc = WndProc ;
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
wndclass.hInstance = hInstance ;
wndclass.hIcon = LoadIcon (NULL,IDI_APPLICATION) ;
wndclass.hCursor = LoadCursor (NULL, IDC_ARROW) ;
wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
wndclass.lpszMenuName = NULL ;
wndclass.lpszClassName = szAppName ;
RegisterClass (&wndclass) ;
}
hwnd = CreateWindow ( szAppName, // class
szWindowText, // window text
WS_OVERLAPPEDWINDOW, // style
CW_USEDEFAULT, CW_USEDEFAULT, // x, y start
CW_USEDEFAULT, CW_USEDEFAULT, // width, height
NULL, // parent window handle
NULL, // menu handle
hInstance, // instance handle
NULL) ; // long pointer to creation data
ShowWindow (hwnd, nCmdShow) ;
UpdateWindow (hwnd) ;
while (GetMessage (&msg, NULL, 0, 0))
{
TranslateMessage (&msg) ;
DispatchMessage (&msg) ;
}
return msg.wParam ;
}